package cn.edu.scau.cmi.dengzejun.chapter10;

import java.io.*;

public class EncryptAndDecrypt {
	String encrypt(String sourceString,String password) {
		char[] p = password.toCharArray();
		int n = p.length;
		char[] c = sourceString.toCharArray();
		int m = c.length;
		for (int k = 0; k<m;++k) {
			int cryptogram = c[k]+p[k%n];
			c[k] = (char)cryptogram;
		}
		return new String(c);
	}
	
	String decrypt(String sourceString,String password) {
		char[] p =password.toCharArray();
		int n =p.length;
		char[] c = sourceString.toCharArray();
		int m = c.length;
		for (int k = 0 ;k<m;++k) {
			int cryptogram = c[k] - p[k%n];
			c[k] = (char)cryptogram;
		}
		return new String(c);
	}
}
